package mobi.greenplate.client.handler;

import mobi.greenplate.client.domain.User;
import mobi.greenplate.client.domain.UserDetail;
import mobi.greenplate.client.converter.UserDetailConverter;
import mobi.greenplate.client.converter.UserConverter;
import mobi.greenplate.client.parser.DomainHandler;

/**
 *
 * @author dmakariev
 */
public class UserDetailHandler extends DomainHandler<UserDetail> {

    private static final String USER_DETAIL_ROOT = "//userDetail";
    private static final String USER_DETAIL_TAG = "userDetail";
    private static final String OWNER_ROOT = "//userDetail/owner";
    private UserDetail userDetail = new UserDetail();
    private User owner = new User();

    @Override
    public UserDetail getEntity() {
        return userDetail;
    }

    @Override
    public void endTag(String parentPath, String tagName, String text) {
        if (parentPath.equalsIgnoreCase(USER_DETAIL_ROOT)) {
            userDetail = UserDetailConverter.endTag(userDetail, tagName, text);
        }
        if (parentPath.equalsIgnoreCase(OWNER_ROOT)) {
            owner = UserConverter.endTag(owner, tagName, text);
        }
        if (tagName.equalsIgnoreCase(USER_DETAIL_TAG)) {
            userDetail.setOwner(owner);
        }
    }

    @Override
    public void startTag(String parentPath, String tagName) {
        //do nothing
    }
}
